package com.ruoyi.project.yingyu.withdraw.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.yingyu.withdraw.domain.UserWithdraw;
import com.ruoyi.project.yingyu.withdraw.service.IUserWithdrawService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 提现管理Controller
 * 
 * @author shixiangwen
 * @date 2020-02-14
 */
@Controller
@RequestMapping("/yingyu/withdraw")
public class UserWithdrawController extends BaseController {
	private String prefix = "yingyu/withdraw";

	@Autowired
	private IUserWithdrawService userWithdrawService;

	@RequiresPermissions("yingyu:withdraw:view")
	@GetMapping()
	public String withdraw() {
		return prefix + "/withdraw";
	}

	/**
	 * 查询提现管理列表
	 */
	@RequiresPermissions("yingyu:withdraw:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(UserWithdraw userWithdraw) {
		startPage();
		List<UserWithdraw> list = userWithdrawService.selectUserWithdrawList(userWithdraw);
		return getDataTable(list);
	}

	/**
	 * 导出提现管理列表
	 */
	@RequiresPermissions("yingyu:withdraw:export")
	@PostMapping("/export")
	@ResponseBody
	public AjaxResult export(UserWithdraw userWithdraw) {
		List<UserWithdraw> list = userWithdrawService.selectUserWithdrawList(userWithdraw);
		ExcelUtil<UserWithdraw> util = new ExcelUtil<UserWithdraw>(UserWithdraw.class);
		return util.exportExcel(list, "withdraw");
	}

	/**
	 * 新增提现管理
	 */
	@GetMapping("/add")
	public String add() {
		return prefix + "/add";
	}

	/**
	 * 新增保存提现管理
	 */
	@RequiresPermissions("yingyu:withdraw:add")
	@Log(title = "提现管理", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(UserWithdraw userWithdraw) {
		return toAjax(userWithdrawService.insertUserWithdraw(userWithdraw));
	}

	/**
	 * 修改提现管理
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Long id, ModelMap mmap) {
		UserWithdraw userWithdraw = userWithdrawService.selectUserWithdrawById(id);
		mmap.put("userWithdraw", userWithdraw);
		return prefix + "/edit";
	}

	/**
	 * 修改保存提现管理
	 */
	@RequiresPermissions("yingyu:withdraw:edit")
	@Log(title = "提现管理", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(UserWithdraw userWithdraw) {
		return toAjax(userWithdrawService.updateUserWithdraw(userWithdraw));
	}

	/**
	 * 删除提现管理
	 */
	@RequiresPermissions("yingyu:withdraw:remove")
	@Log(title = "提现管理", businessType = BusinessType.DELETE)
	@PostMapping("/remove")
	@ResponseBody
	public AjaxResult remove(String ids) {
		return toAjax(userWithdrawService.deleteUserWithdrawByIds(ids));
	}

	/**
	 * 提现申请审核
	 */
	@RequiresPermissions("yingyu:withdraw:approve")
	@Log(title = "提现申请审核", businessType = BusinessType.GRANT)
	@PostMapping("/approve")
	@ResponseBody
	public AjaxResult approve(Long id, Integer status) {
		return toAjax(userWithdrawService.approve(id, status));
	}

	/**
	 * 提现申请转帐
	 */
	@RequiresPermissions("yingyu:withdraw:transfer")
	@Log(title = "提现申请转帐", businessType = BusinessType.GRANT)
	@PostMapping("/transfer")
	@ResponseBody
	public AjaxResult transfer(Long id) {
		return toAjax(userWithdrawService.transfer(id));
	}
}
